
#pragma once
#include <optix.h>
#include <optixu/optixu_math_namespace.h>

__device__ __inline__ float3 tau(const float3 p0, const float3 p1, const float3 sig_a, const float3 sig_e)
{
  using namespace optix;
  return length(p1-p0)*(sig_a+sig_e);
}

__device__ __inline__ float HG_SampleDistance(const float e, const float sig_t)
{
	//ln!
	return -log(1.0-e)/sig_t;
}

__device__ __inline__ float phasefunc(const float cosf)
{
	return 1/M_PIf;
}

int primes[61]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,
83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,
191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283};

inline int rev(const int i,const int p) {if (i==0) return i; else return p-i;}

double hal(const int b, int j) { 
  const int p = primes[b]; 
  double h = 0.0, f = 1.0 / (double)p, fct = f;
  while (j > 0) {
	  h += rev(j % p, p) * fct; 
	  j /= p; 
	  fct *= f;
  } 
  return h;
} 